package com.niuke;

import java.util.Scanner;

/**
 * 34. 学生方阵
 * https://blog.csdn.net/m0_58177653/article/details/130939275
 */
public class NiukeMoni34 {

    public static void main(String[] args) {

        Scanner scanner = new Scanner(System.in);
        String[] size = scanner.nextLine().split(",");

        char[][] input = new char[Integer.parseInt(size[0])][Integer.parseInt(size[1])];
        for (int i = 0; i < input.length; i++) {
            String[] item = scanner.nextLine().split(",");
            char[] row = new char[item.length];
            for (int j = 0; j < row.length; j++) {
                row[j] = item[j].charAt(0);
            }
            input[i] = row;
        }

        int result = 0;
        int[][] dp1 = new int[Integer.parseInt(size[0])][Integer.parseInt(size[1])]; // 横
        int[][] dp2 = new int[Integer.parseInt(size[0])][Integer.parseInt(size[1])]; // 竖
        int[][] dp3 = new int[Integer.parseInt(size[0])][Integer.parseInt(size[1])]; // 正对角线
        int[][] dp4 = new int[Integer.parseInt(size[0])][Integer.parseInt(size[1])]; // 反对角线

        for (int i = 0; i < input.length; i++) {
            char[] row = input[i];
            for (int j = 0; j < row.length; j++) {
                if (row[j] == 'M') {
                    if (j == 0) {
                        dp1[i][j] = 1;
                    } else {
                        dp1[i][j] = dp1[i][j - 1] + 1;
                    }
                    if (i == 0) {
                        dp2[i][j] = 1;
                    } else {
                        dp2[i][j] = dp2[i - 1][j] + 1;
                    }
                    if (i == 0 || j == 0) {
                        dp3[i][j] = 1;
                    } else {
                        dp3[i][j] = dp3[i - 1][j - 1] + 1;
                    }
                } else {
                    dp1[i][j] = 0;
                    dp2[i][j] = 0;
                    dp3[i][j] = 0;
                }
                result = Math.max(result, dp1[i][j]);
                result = Math.max(result, dp2[i][j]);
                result = Math.max(result, dp3[i][j]);
            }
        }

        for (int i = 0; i < input.length; i++) {
            char[] row = input[i];
            for (int j = row.length - 1; j >= 0; j--) {
                if (row[j] == 'M') {
                    if (i == 0 || j == row.length - 1) {
                        dp4[i][j] = 1;
                    } else {
                        dp4[i][j] = dp4[i - 1][j + 1] + 1;
                    }
                } else {
                    dp4[i][j] = 0;
                }
                result = Math.max(result, dp4[i][j]);
            }
        }

        System.out.println(result);
    }

}
